//
// Copyright (c) 2009-2011, chunquedong
//
// This file is part of ChunMap project
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
//
// History:
//   2011-05-03  Jed Young  Creation
//

using gfx
using chunmapData

**
** Renderer
**
@Js
@Serializable
const class Renderer
{
  const Float minScale := 0.000001f
  const Float maxScale := 10E5f

  const Int alpha := 255
  const Bool antialias := false

  private const Symbolizer[] symbolizers

  Int times() { symbolizers.size }

  new makeDef(Symbolizer[] symbolizers)
  {
    this.symbolizers = symbolizers
  }

  new make(|This| f) { f(this) }

  virtual Void startRender(RenderEnv r)
  {
    r.g.push
    if (r.g.alpha != this.alpha) r.g.alpha = this.alpha
    if (r.g.antialias != this.antialias) r.g.antialias = this.antialias
  }

  virtual Void endRender(RenderEnv r){ r.g.pop }

  virtual Void draw(RenderEnv r, Int step)
  {
    symbolizers[step].draw(r)
  }
}